#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    bool lemonadeChange(vector<int>& bills) {
        int five = 0, ten = 0;
        if (bills[0] != 5)
        {
            return false;
        }

        five++;
        for (int i = 1;i < bills.size();i++)
        {
            if (bills[i] == 5)
            {
                five++;
            }

            if (bills[i] == 10)
            {
                if (five == 0)
                {
                    return false;
                }

                five--;
                ten++;

            }

            if (bills[i] == 20)
            {
                if (five == 0)
                {
                    return false;
                }

                else
                {
                    if (ten == 0)
                    {
                        if (five < 3)
                        {
                            return false;
                        }
                        five -= 3;
                    }
                    else
                    {
                        ten--;
                        five--;
                    }
                }

            }

        }
        return true;
    }
};